package com.test.bat;

import java.util.concurrent.TimeUnit;

public class Worker {

	private static WorkThread worker = new WorkThread();

	public static void main(String[] args) {
		if (args.length > 0) {
			if ("-shutdown".equals(args[0])) {
				shutdown();
				return;
			}
		}
		worker.start();
	}

	private static void shutdown() {
		System.out.println("System is shutdowning...");
		worker.shutdown();
		while (worker.isAlive()) {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println("System is shutdown successfully.");
	}
}
